package com.china08.yxyapi.api.comm.bigfileupload;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.YxyLessonsTempRepository;

/**
 * 根据md5和片段 查看是否已经上传过
 * 
 * @author Json
 *
 */
@CrossOrigin
@RestController
public class BigFileCheckBlockController extends YxyApiBaseController {

    @Autowired
    YxyLessonsTempRepository tempRepository;

    @RequestMapping(value = "/api_yw/comm/bigfile/upload/check/block", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel process(@RequestBody ReqModel reqModel) {
        RespModel respModel = new RespModel();
        String md5 = reqModel.md5;
        Integer chunk = reqModel.chunk;
        long count = tempRepository.countByMd5AndChunk(md5, chunk);
        respModel.has = count > 0;
        return respModel;
    }

    public static class RespModel extends YxyApiRespModel {
        public boolean has = false;
    }

    public static class ReqModel extends YxyApiReqModel {
        public String md5;// 整个文件的md5
        public Integer chunk;// 当前第几片
    }

}